package edu.fudan.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * This class represents the basic "user" object in AppFuse that allows for authentication
 * and user management.  It implements Acegi Security's UserDetails interface.
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 *         Updated by Dan Kibler (dan@getrolling.com)
 *         Extended to implement Acegi UserDetails interface
 *         by David Carter david@carter.net
 */
@Entity
@Table(name = "meeting_room")
@Searchable
@XmlRootElement
public class MeetingRoom extends BaseObject implements Serializable {
    private static final long serialVersionUID = 3832626162173359411L;

    private Long id;
    private String name;
    private String location;
    private String description;
    private String telephone;
    private Integer version;
    
    public MeetingRoom() {
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @SearchableId
    public Long getId() {
        return id;
    }

    @Column(nullable = false, length = 50)
    @SearchableProperty
    public String getName() {
        return name;
    }
    
    @Column(nullable = false, length = 50)
    @SearchableProperty
    public String getLocation() {
        return location;
    }
    
    @Column(length = 50)
    @SearchableProperty
    public String getDescription() {
        return description;
    }
    
    @Column(length = 50)
    @SearchableProperty
    public String getTelephone() {
        return telephone;
    }
    
    @Version
    public Integer getVersion() {
        return version;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public void setLocation(String location) {
        this.location = location;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    
    public void setVersion(Integer version) {
        this.version = version;
    }
    
    /**
     * {@inheritDoc}
     */
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof MeetingRoom)) {
            return false;
        }

        final MeetingRoom meetingRoom = (MeetingRoom) o;

        return !(name != null ? !name.equals(meetingRoom.getName()) : meetingRoom.getName() != null);

    }
    
    /**
     * {@inheritDoc}
     */
    public int hashCode() {
        return (name != null ? name.hashCode() : 0);
    }
    
    /**
     * {@inheritDoc}
     */
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
                .append("name", this.name)
                .append("location", this.location)
                .append("description", this.description)
                .append("telephone", this.telephone);
        return sb.toString();
    }
}
